/*
 * This overlay class draws a line to connect GeoPoints on a MapView.
 * Created by Jia De
 */
package com.overlays;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.CornerPathEffect;
import android.graphics.Paint;
import android.graphics.PathEffect;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
import com.route.Route;

public class ViewClaimRouteLine extends Overlay{
    private Context context;
    private Paint paint;
    private Paint backPaint;

    public ViewClaimRouteLine(Context _context){
	super();
	context = _context;
	backPaint = new Paint();
	backPaint.setARGB(200, 200, 200, 200);
	backPaint.setAntiAlias(true);

	paint = new Paint();
	//Color of the path
	paint.setARGB(255, 10, 10, 255);
	paint.setAntiAlias(true);
	paint.setAlpha(90);
	//TODO set path effect
	//paint.setPathEffect();
	paint.setFakeBoldText(true);
	//Width of the path
	paint.setStrokeWidth(6);

    }

    @Override
    public boolean onTap(GeoPoint point, MapView mapView) {
	// Do not react to screen taps.
	return false;
    }

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow){
	if (shadow == false){
	    GeoPoint tempGP = null;
	    Point preTempPoint = new Point();

	    Projection projection = mapView.getProjection();
	    //For each loop to iterate through a list of GeoPoints and join them together. List of GeoPoints is stored in the static class route
	    for (GeoPoint gp : com.claim.Claim.markers) {
		if (tempGP != null) {
		    Point curTempPoint = new Point();
		    projection.toPixels(gp, curTempPoint);
		    canvas.drawLine(preTempPoint.x, preTempPoint.y,
			    curTempPoint.x, curTempPoint.y, paint);
		    tempGP = gp;
		    preTempPoint = curTempPoint;
		} else {
		    tempGP = gp;
		    preTempPoint = projection.toPixels(gp, preTempPoint);
		}
	    }
	}
	super.draw(canvas, mapView, shadow);

    }
}
